package com.ophiux.cs.application.chat.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.cs.application.chat.dto.GetCSMessagesRequest;
import com.ophiux.cs.application.chat.dto.GetCSMessagesResponse;
import com.ophiux.cs.application.chat.service.IQueryCSMessagesAppService;
import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.domain.chat.model.entity.CSChatMessageSend;
import com.ophiux.cs.domain.chat.model.valueobj.CSChatMessageQuery;
import com.ophiux.cs.domain.chat.repositories.ICSChatMessageSendRepository;
import com.ophiux.utils.exception.OphiuxRepositoryException;

/**
 * 聊天记录获取
 * @author chenh
 *
 */
@Service("queryCSMessagesAppService")
public class QueryCSMessagesAppService implements IQueryCSMessagesAppService{

	@Autowired
	private ICSChatMessageSendRepository cSChatMessageSendRepository;	//聊天消息
	
	
	@Override
	public Result<GetCSMessagesResponse> GetCSChatMessages(GetCSMessagesRequest request) {
		
		/**参数合法性验证**/
		if(!request.isParamValid()) {
			return Result.fail("", "参数不合法");
		}
		//构造查询条件
		CSChatMessageQuery query = new CSChatMessageQuery(request.getSESSION_ID(), 
				request.getIS_READ(), request.getPAGE_INDEX(), request.getPAGE_NUM());
		
		List<CSChatMessageSend> csChatRecords = null;
		try {
			csChatRecords = cSChatMessageSendRepository.getCSChatMessageSends(query);
		} catch (OphiuxRepositoryException e) {
			e.printStackTrace();
			return Result.fail("", e.getExceptionMessage());
		}
		
		return Result.success();
	}
	
}
